package com.schoolET.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.schoolET.entity.News;
import com.schoolET.entity.dto.NewsDTO;
import com.schoolET.entity.vo.NewsInfoVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 新闻 Mapper 接口
 * </p>
 *
 * @author lin
 * @since 2024-06-02
 */
@Mapper
public interface NewsMapper extends BaseMapper<News> {

    Page<NewsDTO> getNewsList(Page<?> page, @Param("news")NewsInfoVO newsInfoVO);

    @Insert("insert into news_and_region(news_id,region_id) values(#{newsId},#{regionId})")
    Integer addNewsPosition(@Param("newsId") Integer newsId, @Param("regionId") Integer regionId);

    @Select("select t1.* from news t1 \n" +
            "left join news_and_region t2 \n" +
            "on t1.id = t2.news_id \n" +
            "left join region t3 \n" +
            "on t3.id = t2.region_id \n" +
            "where t3.id = #{regionId} and t1.flag = 0 and t3.flag = 0")
    Page<NewsDTO> getNewsListByRegionId(Page<?> page, @Param("regionId") Integer regionId);

}
